<?php
/**
 * welcome developer.
 * author: liangbo
 * company:tencent suzhou
 * contact:173120209
 * mobile:18550451730
 * Date: 2016-12-18
 * Time: 4:55
 */

class View
{
    protected $variables = array();
    protected $_controller;
    protected $_action;

    function __construct($controller, $action)
    {
        $this->_controller = $controller;
        $this->_action = $action;
    }

    /** 分配变量 **/
    function assign($name, $value)
    {
        $this->variables[$name] = $value;
    }

    /** 渲染显示 **/
    function render()
    {
        extract($this->variables);
        $defaultHeader = APP_PATH . 'application/views/header.php';
        $defaultFooter = APP_PATH . 'application/views/footer.php';
        $controllerHeader = APP_PATH . 'application/views/' . $this->_controller . '/header.php';
        $controllerFooter = APP_PATH . 'application/views/' . $this->_controller . '/footer.php';

        // 页头文件
        if (file_exists($controllerHeader)) {
            include ($controllerHeader);
        } else {
            include ($defaultHeader);
        }

        // 页内容文件
        include (APP_PATH . 'application/views/' . $this->_controller . '/' . $this->_action . '.php');

        // 页脚文件
        if (file_exists($controllerFooter)) {
            include ($controllerFooter);
        } else {
            include ($defaultFooter);
        }
    }
    function  url($array=array())
    {   $url=APP_URL.'/';
        if($this->im($array['c']))
        {


            $url=$url.$array['c'].'/';


        }
        if($this->im($array['a']))
        {



            $url=$url.$array['a'].'/';


        }
        if($this->im($array['k']))
        {
            $html="";
            foreach($array['k'] as $k=>$v )
            {

                $html=$html.$v.'-';



            }
            $html=trim($html,'-');
            if($this->im($html))
            {

                $html=$html.'.'.HTML_PREFIX;


            }
        }


        echo  $url.$html;

    }


    function  im($v)
    {

        if(isset($v)&&!empty($v))
        {

            return true;


        }else{


            return false;



        }





    }

}